In [1]:
%matplotlib inline
from matplotlib import pylab as plt

from metatlas import metatlas_objects
from metatlas import h5_query

import glob, os

import numpy as np

from bokeh.plotting import *
output_notebook()


BokehJS successfully loaded.

Select an experiment


In [2]:
myExperiment = metatlas_objects.get_experiment(name = 'Test_20150722')
len(myExperiment.atlases[-1].compounds)


Out[2]:
54

In [3]:
myExperiment = metatlas_objects.get_experiment(name = 'Test_20150722')

print "Compounds:"
for i,c in enumerate(myExperiment.atlases[-1].compounds):
    print i,c.name,c.mz, c.rt_peak, c.pubchem_id
print ""

print "File Data:"
print len(myExperiment.finfos)
print myExperiment.finfos[0].hdf_file
print myExperiment.finfos[0].group
print myExperiment.finfos[0].polarity


Compounds:
0 DL-Leucine 132.1019056 7.43 857.0
1 DL-Isoleucine 132.1019056 7.75 791.0
2 Leucyl-leucine 245.185969 4.4 94244.0
3 DL-Proline 116.070605 8.66 614.0
4 Pyridoxine 170.081169 2.67 1054.0
5 Betaine 118.086255 6.52 247.0
6 Leu-Val 231.170319 5.53 352038.0
7 Propionyl Carnitine 235.165231 6.5 107738.0
8 Creatinine 114.066188 4.67 588.0
9 Phenylalanine 166.086255 7.54 6140.0
10 Leu-Pro 229.154669 7.38 80817.0
11 Val-Pro 215.139018 7.94 9837272.0
12 Pro-Leu 229.154669 5.97 444109.0
13 Nicotinic acid 124.039304 5.89 938.0
14 Valine 118.086255 8.93 6287.0
15 L-Glutamic Acid 148.060434 13.92 33032.0
16 Leu-Met 263.14239 6.89 118276.0
17 Tyrosine 182.081169 10.03 6057.0
18 Methionine 150.058326 8.59 6137.0
19 Adenosine 268.1040304 4.41 60961.0
20 Histidine 156.0766 14.18 6274.0
21 Tryptophan 205.0971541 8.52 6305.0
22 Adenine 136.0617716 4.33 190.0
23 Dimethylglycine 104.070605 11.94 673.0
24 Threonine 120.0656 11.53 6288.0
25 Alanine 90.0555 11.22 5950.0
26 Serine 106.0501 12.79 5951.0
27 DL-Leucine 132.1019056 7.43 857.0
28 DL-Isoleucine 132.1019056 7.75 791.0
29 Leucyl-leucine 245.185969 4.4 94244.0
30 DL-Proline 116.070605 8.66 614.0
31 Pyridoxine 170.081169 2.67 1054.0
32 Betaine 118.086255 6.52 247.0
33 Leu-Val 231.170319 5.53 352038.0
34 Propionyl Carnitine 235.165231 6.5 107738.0
35 Creatinine 114.066188 4.67 588.0
36 Phenylalanine 166.086255 7.54 6140.0
37 Leu-Pro 229.154669 7.38 80817.0
38 Val-Pro 215.139018 7.94 9837272.0
39 Pro-Leu 229.154669 5.97 444109.0
40 Nicotinic acid 124.039304 5.89 938.0
41 Valine 118.086255 8.93 6287.0
42 L-Glutamic Acid 148.060434 13.92 33032.0
43 Leu-Met 263.14239 6.89 118276.0
44 Tyrosine 182.081169 10.03 6057.0
45 Methionine 150.058326 8.59 6137.0
46 Adenosine 268.1040304 4.41 60961.0
47 Histidine 156.0766 14.18 6274.0
48 Tryptophan 205.0971541 8.52 6305.0
49 Adenine 136.0617716 4.33 190.0
50 Dimethylglycine 104.070605 11.94 673.0
51 Threonine 120.0656 11.53 6288.0
52 Alanine 90.0555 11.22 5950.0
53 Serine 106.0501 12.79 5951.0

File Data:
640
/global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-1.h5
Media
1

In [4]:
# Define a function to help us get 
# MS1 EIC data
# get spectrum near RT-peak
# Get MSMS data for each compound
# get MS1 data and summarize the datapoints
# get heatmap
def get_data_for_a_compound(compound,what_to_get,h5file,polarity):
    """
    A helper function to query the various metatlas data selection 
    commands for a compound defined in an experimental atlas.

    Parameters
    ----------
    compound : a MetAtlas Object for a Compound Class
        this contains the m/z and retention time constraints to select data
    what_to_get : a list of strings
        this contains one or more of [ 'ms1_summary', 'eic', '2dhist', 'msms' ]
    h5_file : str
        Path to input_file
    polarity : int
        [0 or 1] for negative or positive ionzation
    
    Returns
    -------
    """
    #TODO : polarity should be handled in the experiment and not a loose parameter
    import numpy as np
    import metatlas
    import tables
    
    #get a pointer to the hdf5 file
    fid = tables.open_file(h5file)

    #parse varaiables from the metatlas compound object
    name = compound.name
    formula = compound.formula
    adducts = compound.adducts
    mz_theor = compound.mz
    ppm_uncertainty = compound.mz_threshold
    ms_level = 1
    rt_min = compound.rt_min
    rt_max = compound.rt_max
    mz_min = mz_theor - mz_theor * ppm_uncertainty / 1e6
    mz_max = mz_theor + mz_theor * ppm_uncertainty / 1e6
    
    return_data = {}
    return_data['compound'] = {}
    return_data['compound']['name'] = name
    return_data['compound']['formula'] = formula
    return_data['compound']['mz'] = mz_theor
    return_data['compound']['adducts'] = adducts
    
    if 'ms1_summary' in what_to_get:
        #Get Summary Data
        
        #First get MS1 Raw Data
        ms_level=1
        ms1_data = metatlas.get_data(fid, 
                                 ms_level,
                                 polarity,
                                 min_mz=mz_min,
                                 max_mz=mz_max,
                                 min_rt=rt_min,
                                 max_rt=rt_max)
        
        return_data['ms1_summary'] = {}
        return_data['ms1_summary']['mz_centroid'] = np.sum(np.multiply(ms1_data['i'],ms1_data['mz'])) / np.sum(ms1_data['i'])
        return_data['ms1_summary']['rt_centroid'] = np.sum(np.multiply(ms1_data['i'],ms1_data['rt'])) / np.sum(ms1_data['i'])
        idx = np.argmax(ms1_data['i'])
        return_data['ms1_summary']['mz_max'] = ms1_data['mz'][idx]
        return_data['ms1_summary']['rt_max'] = ms1_data['rt'][idx]        
        return_data['ms1_summary']['peak_height'] = ms1_data['i'][idx]
        return_data['ms1_summary']['peak_area'] = np.sum(ms1_data['i'])
    
    if 'eic' in what_to_get:
        #Get Extracted Ion Chromatogram
        # TODO : If a person calls for summary, then they will already have the MS1 raw data
        rt,intensity = metatlas.get_XIC(fid, 
                                        mz_min, 
                                        mz_max,
                                        ms_level,
                                        polarity)
        return_data['eic'] = {}
        return_data['eic']['rt'] = rt
        return_data['eic']['intensity'] = intensity
    
    if '2dhist' in what_to_get:
        #Get 2D histogram of intensity values in m/z and retention time
        mzEdges = np.logspace(np.log10(100),np.log10(1000),10000)
#         mzEdges = np.linspace(mz_theor - 3, mz_theor + 30,100) #TODO : number of mz bins should be an optional parameter
        rtEdges = np.linspace(rt_min,rt_max,100) #TODO : number of rt bins should be an optional parameter. When not provided, it shoulddefauly to unique bins
        ms_level = 1 #TODO : ms_level should be a parameter
        return_data['2dhist'] = {}
        return_data['2dhist'] = metatlas.get_heatmap(fid,mzEdges,rtEdges,ms_level,polarity)
    
    if 'msms' in what_to_get:
        #Get Fragmentation Data
        ms_level=2
        fragmentation_data = metatlas.get_data(fid, 
                                 ms_level,
                                 polarity,
                                 min_mz=0,
                                 max_mz=mz_theor+10,#TODO : this needs to be a parameter
                                 min_rt=rt_min,
                                 max_rt=rt_max,
                                 min_precursor_MZ=mz_min,
                                 max_precursor_MZ=mz_max)
    #                     min_precursor_intensity=0, #TODO : this needs to be a parameter
    #                     max_precursor_intensity=0,#TODO : this needs to be a parameter
    #                     min_collision_energy=0,#TODO : this needs to be a parameter
    #                     max_collision_energy=0)#TODO : this needs to be a parameter
        return_data['msms'] = fragmentation_data

    return return_data

In [11]:
data = get_data_for_a_compound(myExperiment.atlases[-1].compounds[0],
                           ['ms1_summary','2dhist','msms','eic'],
                           myExperiment.finfos[0].hdf_file,
                           myExperiment.finfos[0].polarity)


Querying: (rt >= 6.93) & (rt <= 7.93) & (mz >= 132.100584581) & (mz <= 132.103226619) from ms1_pos
Query complete
Querying: (mz >= 132.100584581) & (mz <= 132.103226619) from ms1_pos
Query complete
Querying: (rt >= 6.93) & (rt <= 7.93) & (mz >= 0) & (mz <= 142.1019056) & (precursor_MZ >= 132.100584581) & (precursor_MZ <= 132.103226619) from ms2_pos
Query complete

In [98]:
# # print data['2dhist']
# N = 20
# m = len(data['2dhist']['rt_bins'])
# n = len(data['2dhist']['mz_bins'])
# z = data['2dhist']['arr'][:]
# z = z / np.amax(z)
# img = np.empty((m,n), dtype=np.uint32)
# view = img.view(dtype=np.uint8).reshape((m, n, 4))
# for i in range(m):
#     for j in range(n):
#         view[i, j, 0] = int(z[i,j] * 255)#255#z[i,j] * 255
#         view[i, j, 1] = int(z[i,j] * 255)
#         view[i, j, 2] = int(z[i,j] * 255)
#         view[i, j, 3] = 255

# # output_file("image_rgba.html", title="image_rgba.py example")

# minx = 6 #np.amin(data['2dhist']['rt_bins'])
# maxx = 7 #np.amax(data['2dhist']['rt_bins'])

# miny = 100 #np.amin(data['2dhist']['mz_bins'])
# maxy = 200 #np.amax(data['2dhist']['mz_bins'])


# p = figure(x_range=[minx, maxx],
#            y_range=[miny, maxy])

# p.image_rgba(image=[img], 
#              x=[minx], y=[miny], 
#              dw=[maxx], dh=[maxy])

# show(p)  # open a browser

In [ ]:
datamat['Adenine'][data,data,data,data]

In [5]:
datamat = []
for i in range(27):
    c = myExperiment.atlases[-1].compounds[i]
    datarow = []
    for j in range(3): # TODO : Because I loaded my files twice, I have 2 times the finfos
        print i,j, myExperiment.finfos[j].hdf_file, c.name
        try:
            data = get_data_for_a_compound(c,
                                       ['msms','2dhist' ,'eic', 'ms1_summary']
                                       myExperiment.finfos[j].hdf_file,
                                       myExperiment.finfos[j].polarity)
            datarow.append(data)
        except: # TODO : A value error is thrown for certain files for compound #2.  There should be a good way to deal with this
            datarow.append('')
    datamat.append(datarow)


0 0 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-1.h5 DL-Leucine
Querying: (rt >= 6.93) & (rt <= 7.93) & (mz >= 0) & (mz <= 142.1019056) & (precursor_MZ >= 132.100584581) & (precursor_MZ <= 132.103226619) from ms2_pos
Query complete
0 1 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-2.h5 DL-Leucine
Querying: (rt >= 6.93) & (rt <= 7.93) & (mz >= 0) & (mz <= 142.1019056) & (precursor_MZ >= 132.100584581) & (precursor_MZ <= 132.103226619) from ms2_pos
Query complete
0 2 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-3.h5 DL-Leucine
Querying: (rt >= 6.93) & (rt <= 7.93) & (mz >= 0) & (mz <= 142.1019056) & (precursor_MZ >= 132.100584581) & (precursor_MZ <= 132.103226619) from ms2_pos
Query complete
1 0 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-1.h5 DL-Isoleucine
Querying: (rt >= 7.25) & (rt <= 8.25) & (mz >= 0) & (mz <= 142.1019056) & (precursor_MZ >= 132.100584581) & (precursor_MZ <= 132.103226619) from ms2_pos
Query complete
1 1 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-2.h5 DL-Isoleucine
Querying: (rt >= 7.25) & (rt <= 8.25) & (mz >= 0) & (mz <= 142.1019056) & (precursor_MZ >= 132.100584581) & (precursor_MZ <= 132.103226619) from ms2_pos
Query complete
1 2 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-3.h5 DL-Isoleucine
Querying: (rt >= 7.25) & (rt <= 8.25) & (mz >= 0) & (mz <= 142.1019056) & (precursor_MZ >= 132.100584581) & (precursor_MZ <= 132.103226619) from ms2_pos
Query complete
2 0 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-1.h5 Leucyl-leucine
Querying: (rt >= 3.9) & (rt <= 4.9) & (mz >= 0) & (mz <= 255.185969) & (precursor_MZ >= 245.173709702) & (precursor_MZ <= 245.198228298) from ms2_pos
Query complete
2 1 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-2.h5 Leucyl-leucine
Querying: (rt >= 3.9) & (rt <= 4.9) & (mz >= 0) & (mz <= 255.185969) & (precursor_MZ >= 245.173709702) & (precursor_MZ <= 245.198228298) from ms2_pos
Query complete
2 2 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-3.h5 Leucyl-leucine
Querying: (rt >= 3.9) & (rt <= 4.9) & (mz >= 0) & (mz <= 255.185969) & (precursor_MZ >= 245.173709702) & (precursor_MZ <= 245.198228298) from ms2_pos
Query complete
3 0 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-1.h5 DL-Proline
Querying: (rt >= 8.16) & (rt <= 9.16) & (mz >= 0) & (mz <= 126.070605) & (precursor_MZ >= 116.069444294) & (precursor_MZ <= 116.071765706) from ms2_pos
Query complete
3 1 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-2.h5 DL-Proline
Querying: (rt >= 8.16) & (rt <= 9.16) & (mz >= 0) & (mz <= 126.070605) & (precursor_MZ >= 116.069444294) & (precursor_MZ <= 116.071765706) from ms2_pos
Query complete
3 2 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-3.h5 DL-Proline
Querying: (rt >= 8.16) & (rt <= 9.16) & (mz >= 0) & (mz <= 126.070605) & (precursor_MZ >= 116.069444294) & (precursor_MZ <= 116.071765706) from ms2_pos
Query complete
4 0 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-1.h5 Pyridoxine
Querying: (rt >= 2.17) & (rt <= 3.17) & (mz >= 0) & (mz <= 180.081169) & (precursor_MZ >= 170.079468188) & (precursor_MZ <= 170.082869812) from ms2_pos
Query complete
4 1 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-2.h5 Pyridoxine
Querying: (rt >= 2.17) & (rt <= 3.17) & (mz >= 0) & (mz <= 180.081169) & (precursor_MZ >= 170.079468188) & (precursor_MZ <= 170.082869812) from ms2_pos
Query complete
4 2 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-3.h5 Pyridoxine
Querying: (rt >= 2.17) & (rt <= 3.17) & (mz >= 0) & (mz <= 180.081169) & (precursor_MZ >= 170.079468188) & (precursor_MZ <= 170.082869812) from ms2_pos
Query complete
5 0 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-1.h5 Betaine
Querying: (rt >= 6.02) & (rt <= 7.02) & (mz >= 0) & (mz <= 128.086255) & (precursor_MZ >= 118.085074137) & (precursor_MZ <= 118.087435863) from ms2_pos
Query complete
5 1 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-2.h5 Betaine
Querying: (rt >= 6.02) & (rt <= 7.02) & (mz >= 0) & (mz <= 128.086255) & (precursor_MZ >= 118.085074137) & (precursor_MZ <= 118.087435863) from ms2_pos
Query complete
5 2 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-3.h5 Betaine
Querying: (rt >= 6.02) & (rt <= 7.02) & (mz >= 0) & (mz <= 128.086255) & (precursor_MZ >= 118.085074137) & (precursor_MZ <= 118.087435863) from ms2_pos
Query complete
6 0 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-1.h5 Leu-Val
Querying: (rt >= 5.03) & (rt <= 6.03) & (mz >= 0) & (mz <= 241.170319) & (precursor_MZ >= 231.168007297) & (precursor_MZ <= 231.172630703) from ms2_pos
Query complete
6 1 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-2.h5 Leu-Val
Querying: (rt >= 5.03) & (rt <= 6.03) & (mz >= 0) & (mz <= 241.170319) & (precursor_MZ >= 231.168007297) & (precursor_MZ <= 231.172630703) from ms2_pos
Query complete
6 2 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-3.h5 Leu-Val
Querying: (rt >= 5.03) & (rt <= 6.03) & (mz >= 0) & (mz <= 241.170319) & (precursor_MZ >= 231.168007297) & (precursor_MZ <= 231.172630703) from ms2_pos
Query complete
7 0 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-1.h5 Propionyl Carnitine
Querying: (rt >= 6.0) & (rt <= 7.0) & (mz >= 0) & (mz <= 245.165231) & (precursor_MZ >= 235.162879348) & (precursor_MZ <= 235.167582652) from ms2_pos
Query complete
7 1 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-2.h5 Propionyl Carnitine
Querying: (rt >= 6.0) & (rt <= 7.0) & (mz >= 0) & (mz <= 245.165231) & (precursor_MZ >= 235.162879348) & (precursor_MZ <= 235.167582652) from ms2_pos
Query complete
7 2 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-3.h5 Propionyl Carnitine
Querying: (rt >= 6.0) & (rt <= 7.0) & (mz >= 0) & (mz <= 245.165231) & (precursor_MZ >= 235.162879348) & (precursor_MZ <= 235.167582652) from ms2_pos
Query complete
8 0 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-1.h5 Creatinine
Querying: (rt >= 4.17) & (rt <= 5.17) & (mz >= 0) & (mz <= 124.066188) & (precursor_MZ >= 114.065047338) & (precursor_MZ <= 114.067328662) from ms2_pos
Query complete
8 1 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-2.h5 Creatinine
Querying: (rt >= 4.17) & (rt <= 5.17) & (mz >= 0) & (mz <= 124.066188) & (precursor_MZ >= 114.065047338) & (precursor_MZ <= 114.067328662) from ms2_pos
Query complete
8 2 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-3.h5 Creatinine
Querying: (rt >= 4.17) & (rt <= 5.17) & (mz >= 0) & (mz <= 124.066188) & (precursor_MZ >= 114.065047338) & (precursor_MZ <= 114.067328662) from ms2_pos
Query complete
9 0 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-1.h5 Phenylalanine
Querying: (rt >= 7.04) & (rt <= 8.04) & (mz >= 0) & (mz <= 176.086255) & (precursor_MZ >= 166.084594137) & (precursor_MZ <= 166.087915863) from ms2_pos
Query complete
9 1 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-2.h5 Phenylalanine
Querying: (rt >= 7.04) & (rt <= 8.04) & (mz >= 0) & (mz <= 176.086255) & (precursor_MZ >= 166.084594137) & (precursor_MZ <= 166.087915863) from ms2_pos
Query complete
9 2 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-3.h5 Phenylalanine
Querying: (rt >= 7.04) & (rt <= 8.04) & (mz >= 0) & (mz <= 176.086255) & (precursor_MZ >= 166.084594137) & (precursor_MZ <= 166.087915863) from ms2_pos
Query complete
10 0 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-1.h5 Leu-Pro
Querying: (rt >= 6.88) & (rt <= 7.88) & (mz >= 0) & (mz <= 239.154669) & (precursor_MZ >= 229.152377453) & (precursor_MZ <= 229.156960547) from ms2_pos
Query complete
10 1 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-2.h5 Leu-Pro
Querying: (rt >= 6.88) & (rt <= 7.88) & (mz >= 0) & (mz <= 239.154669) & (precursor_MZ >= 229.152377453) & (precursor_MZ <= 229.156960547) from ms2_pos
Query complete
10 2 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-3.h5 Leu-Pro
Querying: (rt >= 6.88) & (rt <= 7.88) & (mz >= 0) & (mz <= 239.154669) & (precursor_MZ >= 229.152377453) & (precursor_MZ <= 229.156960547) from ms2_pos
Query complete
11 0 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-1.h5 Val-Pro
Querying: (rt >= 7.44) & (rt <= 8.44) & (mz >= 0) & (mz <= 225.139018) & (precursor_MZ >= 215.13686661) & (precursor_MZ <= 215.14116939) from ms2_pos
Query complete
11 1 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-2.h5 Val-Pro
Querying: (rt >= 7.44) & (rt <= 8.44) & (mz >= 0) & (mz <= 225.139018) & (precursor_MZ >= 215.13686661) & (precursor_MZ <= 215.14116939) from ms2_pos
Query complete
11 2 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-3.h5 Val-Pro
Querying: (rt >= 7.44) & (rt <= 8.44) & (mz >= 0) & (mz <= 225.139018) & (precursor_MZ >= 215.13686661) & (precursor_MZ <= 215.14116939) from ms2_pos
Query complete
12 0 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-1.h5 Pro-Leu
Querying: (rt >= 5.47) & (rt <= 6.47) & (mz >= 0) & (mz <= 239.154669) & (precursor_MZ >= 229.152377453) & (precursor_MZ <= 229.156960547) from ms2_pos
Query complete
12 1 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-2.h5 Pro-Leu
Querying: (rt >= 5.47) & (rt <= 6.47) & (mz >= 0) & (mz <= 239.154669) & (precursor_MZ >= 229.152377453) & (precursor_MZ <= 229.156960547) from ms2_pos
Query complete
12 2 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-3.h5 Pro-Leu
Querying: (rt >= 5.47) & (rt <= 6.47) & (mz >= 0) & (mz <= 239.154669) & (precursor_MZ >= 229.152377453) & (precursor_MZ <= 229.156960547) from ms2_pos
Query complete
13 0 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-1.h5 Nicotinic acid
Querying: (rt >= 5.39) & (rt <= 6.39) & (mz >= 0) & (mz <= 134.039304) & (precursor_MZ >= 124.038063607) & (precursor_MZ <= 124.040544393) from ms2_pos
Query complete
13 1 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-2.h5 Nicotinic acid
Querying: (rt >= 5.39) & (rt <= 6.39) & (mz >= 0) & (mz <= 134.039304) & (precursor_MZ >= 124.038063607) & (precursor_MZ <= 124.040544393) from ms2_pos
Query complete
13 2 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-3.h5 Nicotinic acid
Querying: (rt >= 5.39) & (rt <= 6.39) & (mz >= 0) & (mz <= 134.039304) & (precursor_MZ >= 124.038063607) & (precursor_MZ <= 124.040544393) from ms2_pos
Query complete
14 0 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-1.h5 Valine
Querying: (rt >= 8.43) & (rt <= 9.43) & (mz >= 0) & (mz <= 128.086255) & (precursor_MZ >= 118.085074137) & (precursor_MZ <= 118.087435863) from ms2_pos
Query complete
14 1 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-2.h5 Valine
Querying: (rt >= 8.43) & (rt <= 9.43) & (mz >= 0) & (mz <= 128.086255) & (precursor_MZ >= 118.085074137) & (precursor_MZ <= 118.087435863) from ms2_pos
Query complete
14 2 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-3.h5 Valine
Querying: (rt >= 8.43) & (rt <= 9.43) & (mz >= 0) & (mz <= 128.086255) & (precursor_MZ >= 118.085074137) & (precursor_MZ <= 118.087435863) from ms2_pos
Query complete
15 0 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-1.h5 L-Glutamic Acid
Querying: (rt >= 13.42) & (rt <= 14.42) & (mz >= 0) & (mz <= 158.060434) & (precursor_MZ >= 148.058953396) & (precursor_MZ <= 148.061914604) from ms2_pos
Query complete
15 1 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-2.h5 L-Glutamic Acid
Querying: (rt >= 13.42) & (rt <= 14.42) & (mz >= 0) & (mz <= 158.060434) & (precursor_MZ >= 148.058953396) & (precursor_MZ <= 148.061914604) from ms2_pos
Query complete
15 2 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-3.h5 L-Glutamic Acid
Querying: (rt >= 13.42) & (rt <= 14.42) & (mz >= 0) & (mz <= 158.060434) & (precursor_MZ >= 148.058953396) & (precursor_MZ <= 148.061914604) from ms2_pos
Query complete
16 0 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-1.h5 Leu-Met
Querying: (rt >= 6.39) & (rt <= 7.39) & (mz >= 0) & (mz <= 273.14239) & (precursor_MZ >= 263.139758576) & (precursor_MZ <= 263.145021424) from ms2_pos
16 1 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-2.h5 Leu-Met
Querying: (rt >= 6.39) & (rt <= 7.39) & (mz >= 0) & (mz <= 273.14239) & (precursor_MZ >= 263.139758576) & (precursor_MZ <= 263.145021424) from ms2_pos
Query complete
16 2 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-3.h5 Leu-Met
Querying: (rt >= 6.39) & (rt <= 7.39) & (mz >= 0) & (mz <= 273.14239) & (precursor_MZ >= 263.139758576) & (precursor_MZ <= 263.145021424) from ms2_pos
17 0 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-1.h5 Tyrosine
Querying: (rt >= 9.53) & (rt <= 10.53) & (mz >= 0) & (mz <= 192.081169) & (precursor_MZ >= 182.079348188) & (precursor_MZ <= 182.082989812) from ms2_pos
Query complete
17 1 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-2.h5 Tyrosine
Querying: (rt >= 9.53) & (rt <= 10.53) & (mz >= 0) & (mz <= 192.081169) & (precursor_MZ >= 182.079348188) & (precursor_MZ <= 182.082989812) from ms2_pos
Query complete
17 2 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-3.h5 Tyrosine
Querying: (rt >= 9.53) & (rt <= 10.53) & (mz >= 0) & (mz <= 192.081169) & (precursor_MZ >= 182.079348188) & (precursor_MZ <= 182.082989812) from ms2_pos
Query complete
18 0 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-1.h5 Methionine
Querying: (rt >= 8.09) & (rt <= 9.09) & (mz >= 0) & (mz <= 160.058326) & (precursor_MZ >= 150.056825417) & (precursor_MZ <= 150.059826583) from ms2_pos
Query complete
18 1 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-2.h5 Methionine
Querying: (rt >= 8.09) & (rt <= 9.09) & (mz >= 0) & (mz <= 160.058326) & (precursor_MZ >= 150.056825417) & (precursor_MZ <= 150.059826583) from ms2_pos
Query complete
18 2 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-3.h5 Methionine
Querying: (rt >= 8.09) & (rt <= 9.09) & (mz >= 0) & (mz <= 160.058326) & (precursor_MZ >= 150.056825417) & (precursor_MZ <= 150.059826583) from ms2_pos
Query complete
19 0 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-1.h5 Adenosine
Querying: (rt >= 3.91) & (rt <= 4.91) & (mz >= 0) & (mz <= 278.1040304) & (precursor_MZ >= 268.10134936) & (precursor_MZ <= 268.10671144) from ms2_pos
19 1 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-2.h5 Adenosine
Querying: (rt >= 3.91) & (rt <= 4.91) & (mz >= 0) & (mz <= 278.1040304) & (precursor_MZ >= 268.10134936) & (precursor_MZ <= 268.10671144) from ms2_pos
Query complete
19 2 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-3.h5 Adenosine
Querying: (rt >= 3.91) & (rt <= 4.91) & (mz >= 0) & (mz <= 278.1040304) & (precursor_MZ >= 268.10134936) & (precursor_MZ <= 268.10671144) from ms2_pos
Query complete
20 0 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-1.h5 Histidine
Querying: (rt >= 13.68) & (rt <= 14.68) & (mz >= 0) & (mz <= 166.0766) & (precursor_MZ >= 156.075039234) & (precursor_MZ <= 156.078160766) from ms2_pos
Query complete
20 1 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-2.h5 Histidine
Querying: (rt >= 13.68) & (rt <= 14.68) & (mz >= 0) & (mz <= 166.0766) & (precursor_MZ >= 156.075039234) & (precursor_MZ <= 156.078160766) from ms2_pos
Query complete
20 2 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-3.h5 Histidine
Querying: (rt >= 13.68) & (rt <= 14.68) & (mz >= 0) & (mz <= 166.0766) & (precursor_MZ >= 156.075039234) & (precursor_MZ <= 156.078160766) from ms2_pos
Query complete
21 0 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-1.h5 Tryptophan
Querying: (rt >= 8.02) & (rt <= 9.02) & (mz >= 0) & (mz <= 215.0971541) & (precursor_MZ >= 205.095103128) & (precursor_MZ <= 205.099205072) from ms2_pos
Query complete
21 1 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-2.h5 Tryptophan
Querying: (rt >= 8.02) & (rt <= 9.02) & (mz >= 0) & (mz <= 215.0971541) & (precursor_MZ >= 205.095103128) & (precursor_MZ <= 205.099205072) from ms2_pos
Query complete
21 2 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-3.h5 Tryptophan
Querying: (rt >= 8.02) & (rt <= 9.02) & (mz >= 0) & (mz <= 215.0971541) & (precursor_MZ >= 205.095103128) & (precursor_MZ <= 205.099205072) from ms2_pos
Query complete
22 0 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-1.h5 Adenine
Querying: (rt >= 3.83) & (rt <= 4.83) & (mz >= 0) & (mz <= 146.0617716) & (precursor_MZ >= 136.060410982) & (precursor_MZ <= 136.063132218) from ms2_pos
Query complete
22 1 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-2.h5 Adenine
Querying: (rt >= 3.83) & (rt <= 4.83) & (mz >= 0) & (mz <= 146.0617716) & (precursor_MZ >= 136.060410982) & (precursor_MZ <= 136.063132218) from ms2_pos
Query complete
22 2 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-3.h5 Adenine
Querying: (rt >= 3.83) & (rt <= 4.83) & (mz >= 0) & (mz <= 146.0617716) & (precursor_MZ >= 136.060410982) & (precursor_MZ <= 136.063132218) from ms2_pos
23 0 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-1.h5 Dimethylglycine
Querying: (rt >= 11.44) & (rt <= 12.44) & (mz >= 0) & (mz <= 114.070605) & (precursor_MZ >= 104.069564294) & (precursor_MZ <= 104.071645706) from ms2_pos
Query complete
23 1 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-2.h5 Dimethylglycine
Querying: (rt >= 11.44) & (rt <= 12.44) & (mz >= 0) & (mz <= 114.070605) & (precursor_MZ >= 104.069564294) & (precursor_MZ <= 104.071645706) from ms2_pos
Query complete
23 2 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-3.h5 Dimethylglycine
Querying: (rt >= 11.44) & (rt <= 12.44) & (mz >= 0) & (mz <= 114.070605) & (precursor_MZ >= 104.069564294) & (precursor_MZ <= 104.071645706) from ms2_pos
Query complete
24 0 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-1.h5 Threonine
Querying: (rt >= 11.03) & (rt <= 12.03) & (mz >= 0) & (mz <= 130.0656) & (precursor_MZ >= 120.064399344) & (precursor_MZ <= 120.066800656) from ms2_pos
Query complete
24 1 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-2.h5 Threonine
Querying: (rt >= 11.03) & (rt <= 12.03) & (mz >= 0) & (mz <= 130.0656) & (precursor_MZ >= 120.064399344) & (precursor_MZ <= 120.066800656) from ms2_pos
Query complete
24 2 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-3.h5 Threonine
Querying: (rt >= 11.03) & (rt <= 12.03) & (mz >= 0) & (mz <= 130.0656) & (precursor_MZ >= 120.064399344) & (precursor_MZ <= 120.066800656) from ms2_pos
Query complete
25 0 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-1.h5 Alanine
Querying: (rt >= 10.72) & (rt <= 11.72) & (mz >= 0) & (mz <= 100.0555) & (precursor_MZ >= 90.054599445) & (precursor_MZ <= 90.056400555) from ms2_pos
25 1 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-2.h5 Alanine
Querying: (rt >= 10.72) & (rt <= 11.72) & (mz >= 0) & (mz <= 100.0555) & (precursor_MZ >= 90.054599445) & (precursor_MZ <= 90.056400555) from ms2_pos
Query complete
25 2 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-3.h5 Alanine
Querying: (rt >= 10.72) & (rt <= 11.72) & (mz >= 0) & (mz <= 100.0555) & (precursor_MZ >= 90.054599445) & (precursor_MZ <= 90.056400555) from ms2_pos
26 0 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-1.h5 Serine
Querying: (rt >= 12.29) & (rt <= 13.29) & (mz >= 0) & (mz <= 116.0501) & (precursor_MZ >= 106.049039499) & (precursor_MZ <= 106.051160501) from ms2_pos
Query complete
26 1 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-2.h5 Serine
Querying: (rt >= 12.29) & (rt <= 13.29) & (mz >= 0) & (mz <= 116.0501) & (precursor_MZ >= 106.049039499) & (precursor_MZ <= 106.051160501) from ms2_pos
Query complete
26 2 /global/homes/b/bpb/ExoMetabolomic_Example_Data/MEDIA-3.h5 Serine
Querying: (rt >= 12.29) & (rt <= 13.29) & (mz >= 0) & (mz <= 116.0501) & (precursor_MZ >= 106.049039499) & (precursor_MZ <= 106.051160501) from ms2_pos
Query complete

In [6]:
print len(datamat)
print len(datamat[0])
# print datamat[15][15].keys()

flist = ['msms','compound']
import pickle
data = {}
for i,d in enumerate(datamat):
    try:
        print i,d[0].keys()
        data[d[0]['compound']['name']] = d[0]['msms']
    except:
        pass

        
# with open('savedata.pickle', 'wb') as handle:
#     pickle.dump(data, handle)

# with open('filename.pickle', 'rb') as handle:
#   datamat = pickle.load(handle)


27
3
0 ['msms', 'compound']
1 ['msms', 'compound']
2 ['msms', 'compound']
3 ['msms', 'compound']
4 ['msms', 'compound']
5 ['msms', 'compound']
6 ['msms', 'compound']
7 ['msms', 'compound']
8 ['msms', 'compound']
9 ['msms', 'compound']
10 ['msms', 'compound']
11 ['msms', 'compound']
12 ['msms', 'compound']
13 ['msms', 'compound']
14 ['msms', 'compound']
15 ['msms', 'compound']
16 17 ['msms', 'compound']
18 ['msms', 'compound']
19 20 ['msms', 'compound']
21 ['msms', 'compound']
22 ['msms', 'compound']
23 ['msms', 'compound']
24 ['msms', 'compound']
25 26 ['msms', 'compound']

In [8]:
# create a new plot with a title and axis labels

# x = data['msms']['mz']
# y0 = np.zeros(data['msms']['i'].shape)
# y =  data['msms']['i']
key = 'Adenine'
x = data[key]['mz']
y0 = np.zeros(data[key]['i'].shape)
y =  data[key]['i']

p1 = figure(title='MS/MS data for %s'%key, x_axis_label='m/z', y_axis_label='Intensity',plot_width=800, plot_height=400)
p1.segment(x, y0, x, y, line_width=2, line_color="black", )
# p1.circle(x, y, size=5, fill_color="orange", line_color="green", line_width=2, )
show(vplot(p1))



In [37]:
# create a new plot with a title and axis labels

# x = data['msms']['mz']
# y0 = np.zeros(data['msms']['i'].shape)
# y =  data['msms']['i']
metIdx = 21
fileIdx = 0
x = datamat[metIdx][fileIdx]['msms']['mz']
y0 = np.zeros(datamat[metIdx][fileIdx]['msms']['i'].shape)
y =  datamat[metIdx][fileIdx]['msms']['i']

p1 = figure(title='MS/MS data for %s'%datamat[metIdx][fileIdx]['compound']['name'], x_axis_label='m/z', y_axis_label='Intensity',plot_width=800, plot_height=400)
p1.segment(x, y0, x, y, line_width=2, line_color="black", )
# p1.circle(x, y, size=5, fill_color="orange", line_color="green", line_width=2, )
show(vplot(p1))



In [19]:
print datamat[10][0]['msms']


{'rt': array([ 6.88417339,  6.88417339,  6.88417339,  6.88417339,  6.88417339,
        6.88417339,  6.88417339,  6.88417339,  6.88417339,  6.88417339,
        6.88417339,  6.88417339,  6.88417339,  6.88417339,  6.88417339,
        6.88417339,  6.88417339,  6.88417339,  6.88417339,  7.06354856,
        7.06354856,  7.06354856,  7.06354856,  7.06354856,  7.06354856,
        7.06354856,  7.06354856,  7.06354856,  7.06354856,  7.06354856,
        7.06354856,  7.06354856,  7.06354856,  7.06354856,  7.06354856,
        7.06354856,  7.06354856,  7.06354856,  7.06354856,  7.06354856,
        7.06354856,  7.06354856,  7.06354856,  7.06354856,  7.06354856,
        7.06354856,  7.06354856,  7.06354856,  7.06354856,  7.06354856,
        7.06354856,  7.06354856,  7.23624659,  7.23624659,  7.23624659,
        7.23624659,  7.23624659,  7.23624659,  7.23624659,  7.23624659,
        7.23624659,  7.23624659,  7.23624659,  7.23624659,  7.23624659,
        7.23624659,  7.23624659,  7.23624659,  7.23624659,  7.23624659,
        7.23624659,  7.23624659,  7.23624659,  7.23624659,  7.23624659,
        7.23624659,  7.23624659,  7.23624659,  7.23624659,  7.23624659,
        7.23624659,  7.23624659,  7.23624659,  7.23624659,  7.23624659,
        7.23624659,  7.23624659,  7.23624659,  7.23624659,  7.23624659,
        7.23624659,  7.23624659,  7.23624659,  7.23624659,  7.23624659,
        7.23624659,  7.41236782,  7.41236782,  7.41236782,  7.41236782,
        7.41236782,  7.41236782,  7.41236782,  7.41236782,  7.41236782,
        7.41236782,  7.41236782,  7.41236782,  7.41236782,  7.41236782,
        7.41236782,  7.41236782,  7.41236782,  7.41236782,  7.41236782,
        7.41236782,  7.41236782,  7.41236782,  7.41236782,  7.41236782,
        7.41236782,  7.41236782,  7.41236782,  7.41236782,  7.41236782,
        7.41236782,  7.41236782,  7.41236782,  7.41236782,  7.41236782,
        7.41236782,  7.41236782,  7.41236782,  7.41236782,  7.41236782,
        7.41236782,  7.41236782,  7.41236782,  7.41236782,  7.41236782,
        7.41236782,  7.41236782,  7.41236782,  7.41236782,  7.41236782,
        7.41236782,  7.41236782,  7.58425331,  7.58425331,  7.58425331,
        7.58425331,  7.58425331,  7.58425331,  7.58425331,  7.58425331,
        7.58425331,  7.58425331,  7.58425331,  7.58425331,  7.58425331,
        7.58425331,  7.58425331,  7.58425331,  7.58425331,  7.58425331,
        7.58425331,  7.58425331,  7.58425331,  7.58425331,  7.58425331,
        7.58425331,  7.58425331,  7.58425331,  7.58425331,  7.58425331,
        7.58425331,  7.58425331,  7.58425331,  7.58425331,  7.58425331,
        7.58425331,  7.58425331,  7.58425331,  7.58425331,  7.58425331,
        7.58425331,  7.58425331,  7.58425331,  7.58425331,  7.58425331,
        7.58425331,  7.58425331,  7.58425331,  7.58425331,  7.58425331,
        7.58425331,  7.58425331,  7.58425331,  7.58425331,  7.58425331,
        7.58425331,  7.58425331,  7.58425331,  7.58425331,  7.58425331,
        7.58425331,  7.58425331,  7.58425331,  7.58425331,  7.58425331,
        7.58425331,  7.75780916,  7.75780916,  7.75780916,  7.75780916,
        7.75780916,  7.75780916,  7.75780916,  7.75780916,  7.75780916,
        7.75780916,  7.75780916,  7.75780916,  7.75780916,  7.75780916,
        7.75780916,  7.75780916,  7.75780916,  7.75780916,  7.75780916,
        7.75780916,  7.75780916,  7.75780916,  7.75780916,  7.75780916,
        7.75780916,  7.75780916,  7.75780916,  7.75780916,  7.75780916,
        7.75780916,  7.75780916,  7.75780916,  7.75780916,  7.75780916,
        7.75780916,  7.75780916,  7.75780916,  7.75780916,  7.75780916,
        7.75780916,  7.75780916,  7.75780916,  7.75780916,  7.75780916,
        7.75780916,  7.75780916,  7.75780916,  7.75780916,  7.75780916,
        7.75780916,  7.75780916,  7.75780916,  7.75780916,  7.75780916,
        7.75780916], dtype=float32), 'i': array([  1.05258564e+04,   1.34718379e+04,   1.29169414e+04,
         7.39337700e+06,   2.26710410e+04,   3.25753844e+05,
         1.83645020e+04,   1.43092949e+04,   4.20922656e+05,
         1.37246104e+04,   1.46161182e+04,   6.17715375e+05,
         1.62706348e+04,   6.30156836e+04,   2.89679344e+05,
         2.82377031e+04,   3.59718000e+06,   4.64871656e+05,
         2.89027305e+04,   9.48013281e+03,   1.01166162e+04,
         1.09503633e+04,   1.08176133e+04,   9.66579688e+03,
         6.12340000e+06,   2.61616445e+04,   2.65417031e+05,
         1.64395176e+04,   1.26508301e+04,   2.14784672e+05,
         1.06283770e+04,   1.02307949e+04,   1.05012266e+04,
         1.09404736e+04,   1.15974199e+04,   3.20951906e+05,
         1.16909863e+04,   2.20548574e+04,   1.20918838e+04,
         2.20445566e+04,   1.43273115e+04,   1.09649508e+05,
         1.62516562e+04,   1.92836172e+05,   1.18117510e+04,
         1.24107568e+04,   4.82858594e+04,   2.92685775e+06,
         4.46199844e+05,   1.99272988e+04,   1.39764238e+04,
         1.19520781e+04,   4.85776074e+03,   4.68828564e+03,
         3.08019600e+06,   4.89887842e+03,   1.36791938e+05,
         1.87979961e+04,   1.19786562e+05,   6.70981299e+03,
         4.81944482e+03,   5.45870938e+04,   2.18536582e+04,
         4.59394336e+03,   1.73523766e+05,   5.24757266e+04,
         7.11579639e+03,   5.74165771e+03,   4.61316797e+03,
         6.13996777e+03,   1.10571416e+04,   2.44360391e+04,
         2.10157500e+04,   6.65569189e+03,   1.24995336e+05,
         5.01343848e+03,   5.18398389e+03,   6.39379590e+03,
         8.77235625e+04,   8.43323730e+03,   8.11234668e+03,
         4.92761562e+04,   2.39157148e+04,   3.01072305e+04,
         5.20672803e+03,   8.82839551e+03,   7.80853906e+03,
         5.00897500e+04,   2.28590469e+04,   1.46029138e+06,
         4.20279453e+04,   1.83298234e+05,   3.43125078e+04,
         3.70681719e+04,   5.15857178e+03,   6.33832568e+03,
         2.80504883e+03,   2.80877661e+03,   2.44161108e+03,
         2.64286011e+03,   1.86514625e+06,   4.60935498e+03,
         7.87465000e+04,   2.56688125e+04,   2.74087085e+03,
         2.90069995e+03,   7.98967266e+04,   3.40900024e+03,
         3.56125898e+04,   9.33020625e+04,   3.96581226e+03,
         1.16540684e+04,   1.10918891e+05,   1.91924336e+04,
         1.20727812e+04,   4.13907275e+03,   1.29973193e+04,
         4.81394922e+03,   3.37171313e+03,   3.63813594e+04,
         4.74750195e+03,   5.47404609e+04,   4.58988379e+03,
         4.03467285e+03,   1.84785938e+04,   1.60830977e+04,
         6.23921826e+03,   3.24467236e+03,   3.98107007e+03,
         3.08540527e+03,   4.14658936e+03,   2.34343926e+04,
         1.18853369e+04,   4.09207520e+03,   3.50171606e+03,
         4.41645752e+03,   6.21946533e+03,   4.24598633e+03,
         8.46878875e+05,   1.54377725e+04,   1.23925703e+05,
         1.76774078e+05,   3.66617261e+03,   5.32802539e+03,
         7.30013379e+03,   2.11795605e+04,   5.03756250e+03,
         1.40271497e+03,   1.31846887e+03,   1.46981799e+03,
         1.48348657e+03,   1.44277490e+03,   1.48891089e+03,
         5.14943750e+05,   1.96317305e+04,   2.10294263e+03,
         2.50380723e+04,   1.88678809e+03,   2.12841309e+03,
         6.38957969e+04,   1.73362317e+03,   1.57707959e+03,
         5.15866641e+04,   1.52971484e+05,   3.42903149e+03,
         2.94254199e+04,   1.06340967e+04,   1.72956030e+03,
         2.04539734e+03,   7.39942969e+04,   4.38978359e+04,
         7.34221094e+03,   7.82753955e+03,   2.30811768e+03,
         3.05505322e+03,   3.38433867e+04,   1.84559924e+03,
         2.10001709e+03,   4.12291113e+03,   4.56440527e+03,
         1.09044258e+04,   2.78375659e+03,   2.23010425e+03,
         2.30142871e+04,   2.53934717e+03,   3.96481104e+03,
         2.63343262e+03,   1.00808457e+04,   2.39002539e+03,
         3.22781250e+03,   3.19808472e+03,   2.12285815e+03,
         1.14442363e+04,   4.11476660e+03,   1.90032178e+03,
         1.26896543e+04,   2.83878247e+03,   2.43364209e+03,
         4.27319043e+03,   1.01576074e+04,   8.93252344e+03,
         1.01096943e+04,   2.44586401e+03,   2.84962938e+05,
         1.85316211e+04,   4.15810977e+04,   3.03100094e+05,
         7.62297266e+03,   5.15768945e+03,   2.54776758e+04,
         3.91229712e+03,   1.67666235e+03,   3.29609351e+03,
         1.65824805e+03,   1.92796141e+05,   7.89995850e+03,
         1.11075518e+04,   2.09071729e+03,   6.59563184e+03,
         1.75257117e+03,   4.69544688e+04,   1.59515991e+03,
         5.47498086e+04,   1.96510391e+04,   1.69146118e+03,
         3.20283828e+04,   1.61549097e+03,   1.80486487e+03,
         5.33978867e+04,   3.21816382e+03,   5.34254922e+04,
         1.78953613e+03,   4.16341016e+03,   3.65271899e+03,
         3.78261367e+04,   1.54226135e+03,   1.84113318e+03,
         3.13169727e+03,   2.16581323e+03,   1.20324902e+04,
         1.94467065e+03,   5.79391699e+03,   2.27728589e+03,
         8.23846289e+03,   2.08482397e+03,   6.69606836e+03,
         2.43765308e+03,   1.23546426e+04,   1.99658145e+04,
         2.03489136e+03,   2.41532593e+03,   3.81021143e+03,
         1.31270117e+04,   2.27976782e+03,   8.18470996e+03,
         1.03005801e+04,   5.70341133e+04,   2.33425952e+03,
         3.29261157e+03,   1.12811773e+05,   2.72625020e+04,
         1.51341357e+04,   4.22679375e+04,   2.45813330e+03,
         2.98623975e+03,   3.31536426e+03], dtype=float32), 'mz': array([  50.24006271,   57.10220337,   62.21100616,   70.06620789,
         71.0633316 ,   71.06951141,   72.08171844,   78.82743073,
         86.09741211,   90.47826385,  109.75698853,  116.07141113,
        117.07515717,  132.10235596,  183.14996338,  184.15325928,
        229.15557861,  230.15887451,  231.1599884 ,   52.48904037,
         58.39954758,   59.3013382 ,   60.51889801,   63.17871857,
         70.06613159,   71.06323242,   71.06939697,   71.07271576,
         72.08154297,   86.09733582,   87.64891815,   97.91241455,
        101.2438736 ,  101.93828583,  104.69573975,  116.07126617,
        117.07522583,  130.06562805,  130.35798645,  132.10246277,
        144.08210754,  158.09701538,  181.13352966,  183.14993286,
        210.92021179,  212.84989929,  214.0871582 ,  229.15531921,
        230.15882874,  231.11274719,  231.16278076,  232.58944702,
         69.60531616,   69.67151642,   70.06613922,   70.57423401,
         71.06944275,   72.08167267,   86.09728241,   87.6490097 ,
         93.91451263,   98.97612   ,  100.07630157,  102.76013947,
        116.07128143,  116.98664856,  117.07453156,  127.24995422,
        128.44049072,  129.13943481,  130.06555176,  132.10243225,
        134.99655151,  158.08473206,  158.09698486,  160.06513977,
        164.0667572 ,  183.11280823,  183.14993286,  183.16505432,
        184.15170288,  188.07159424,  189.04423523,  206.07102966,
        207.05610657,  211.10920715,  211.14471436,  214.08647156,
        224.08082581,  229.15536499,  230.07145691,  230.15844727,
        230.18621826,  231.11529541,  231.13398743,  231.1612854 ,
         55.93689728,   56.19346619,   57.45013428,   59.18671036,
         70.06616211,   71.06336975,   71.06945801,   72.08179474,
         79.01767731,   82.74518585,   86.09740448,   87.10055542,
         98.97619629,  100.07646179,  105.03742981,  114.0915451 ,
        116.07133484,  116.98661041,  129.13916016,  130.06549072,
        132.10258484,  134.99710083,  138.89433289,  158.09695435,
        183.11418152,  183.15003967,  184.15246582,  188.05664062,
        188.07144165,  189.04388428,  206.07028198,  207.05496216,
        211.14587402,  213.16023254,  213.207901  ,  214.08683777,
        224.08169556,  227.13905334,  228.08827209,  228.1459198 ,
        228.17149353,  228.23419189,  229.15544128,  230.07061768,
        230.15884399,  230.18708801,  230.24986267,  231.0851593 ,
        231.11300659,  231.18988037,  231.21711731,   51.98277283,
         56.25107574,   56.98191452,   60.81560135,   62.50511169,
         66.89859772,   70.06620026,   71.06945801,   72.04562378,
         72.08182526,   84.04571533,   84.08175659,   86.09738922,
         95.53397369,   97.2951889 ,   98.97618866,  100.0765686 ,
        101.07978821,  105.03759003,  114.09220123,  114.21636963,
        114.96191406,  116.07133484,  116.98666382,  117.07471466,
        129.139328  ,  131.11834717,  132.10224915,  134.99684143,
        139.80290222,  153.00805664,  157.13368225,  158.09666443,
        165.10289001,  181.09681702,  181.13279724,  183.14976501,
        188.07136536,  189.04405212,  189.12385559,  206.07113647,
        207.01728821,  209.09255981,  211.14421082,  212.03808594,
        213.16073608,  213.20814514,  214.08656311,  224.08164978,
        227.10437012,  228.1434021 ,  228.17041016,  228.23266602,
        229.06585693,  229.11878967,  229.13143921,  229.15556335,
        230.07049561,  230.15936279,  230.18702698,  231.08441162,
        231.11203003,  231.19030762,  231.2164917 ,   55.65330124,
         56.96591949,   58.4059906 ,   70.066185  ,   71.06950378,
         72.08188629,   79.59881592,   84.08152771,   84.59996033,
         86.09734344,   95.11612701,   98.97615051,  100.07666016,
        104.77722168,  105.03779602,  112.11236572,  116.00230408,
        116.07141113,  116.97914886,  116.98667908,  125.07099152,
        129.13865662,  134.01309204,  134.99714661,  138.641922  ,
        143.29580688,  153.0078125 ,  157.1338501 ,  165.10281372,
        173.92227173,  183.15037537,  186.05935669,  186.10345459,
        188.06069946,  189.04443359,  189.12382507,  206.07069397,
        212.03849792,  213.04277039,  213.1608429 ,  213.20812988,
        224.08068848,  227.13938904,  228.17243958,  228.23258972,
        229.06506348,  229.08740234,  229.12059021,  229.15553284,
        230.07023621,  230.1587677 ,  230.18699646,  230.2492218 ,
        231.19154358,  231.21748352], dtype=float32)}

In [19]:
# for datarow in datamat:
from itertools import groupby
plt.figure(num=None, figsize=(24, 7), dpi=80, facecolor='w', edgecolor='k')

# fig = plt.figure(figsize=(30,5))
for j,mycompound in enumerate(myExperiment.atlases[3].compounds):

    datarow = datamat[j]
    myVals = []
    for i,myFile in enumerate(datarow):
        try:
            myVals.append((myExperiment.finfos[i].group, myFile['peak_area']))
        except:
            myVals.append((myExperiment.finfos[i].group, 0))
    myVals = sorted(myVals, key=lambda x: x[0]) 

    data_to_plot = []
    groupName = []
    for key, group in groupby(myVals, lambda x: x[0]):
        L = list(zip(*group)[1])
        data_to_plot.append(L)
        groupName.append(key)
    plt.subplot(9,3,j+1)

    bp = plt.boxplot(data_to_plot)
    ax = plt.gca()
    ax.set_xticklabels(groupName)
    ax.set_title(mycompound.name)
    ax.set_ylabel('peak area')
plt.show()



In [ ]: